home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / disk / cdrom / MCDPlay.lha / MCDPlayer / Source / Windows.c < prev   
C/C++ Source or Header  |  1994-12-22  |  7KB  |  254 lines

  1. #include "mcdplayer.h"
  2. #include "mcdplayer_gui.h"
  3.  
  4. struct Gadget *MainGadget[31];
  5.  
  6. WORD gad_x[] = { 267, 288, 309, 330, 351, 267, 288, 309, 330, 351, 267, 288, 309, 330, 351,
  7.                  267, 288, 309, 330, 351, 267, 302, 336,   7,  52,  77, 102, 137, 172, 207,
  8.                  242 };
  9.  
  10. WORD gad_y[] = {   6,   6,   6,   6,   6,  18,  18,  18,  18,  18,  30,  30,  30,  30,  30,
  11.                   42,  42,  42,  42,  42,  53,  53,  53,  65,  65,  65,  65,  65,  65,  65,
  12.                   65 };
  13.  
  14. WORD gad_w[] = {  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,
  15.                   19,  19,  19,  19,  19,  34,  33,  34,  44,  24,  24,  34,  34,  34,  34,
  16.                   23 };
  17.  
  18. WORD gad_h[] = {   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,
  19.                    9,   9,   9,   9,   9,  11,  11,  11,  13,  13,  13,  13,  13,  13,  13,
  20.                   13 };
  21.  
  22. UWORD offy = 0;
  23.  
  24. struct TagItem    MainWindowTags[] = {
  25.     WA_Left,          0,
  26.     WA_Top,           0,
  27.     WA_Width,         390,
  28.     WA_Height,        0,
  29.     WA_IDCMP,         IDCMP_GADGETUP|IDCMP_REFRESHWINDOW|IDCMP_CLOSEWINDOW,
  30.     WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  31.     WA_Gadgets,       0l,
  32.     WA_Title,         "MCDPlayer V" VERSION,
  33.     WA_ScreenTitle,   0l,
  34.     WA_PubScreen,     NULL,
  35.     TAG_DONE };
  36.  
  37. struct Image MainImage = {
  38.     0,0,382,84,2,
  39.     NULL,
  40.     0x3,0x0,NULL
  41.     };
  42.  
  43. struct Image PfeilImage = {
  44.     0,0,9,5,2,
  45.     NULL,
  46.     0x3,0x0,NULL
  47.     };
  48.  
  49. struct Image PauseImage = {
  50.     0,0,9,5,2,
  51.     NULL,
  52.     0x3,0x0,NULL
  53.     };
  54.  
  55. struct Image PrgmImage = {
  56.     0,0,21,5,2,
  57.     NULL,
  58.     0x3,0x0,NULL
  59.     };
  60.  
  61. char FontName[130];
  62.  
  63. struct TextAttr DispFont = {
  64.     &FontName[0], 10, 0x00, 0x01 };
  65.  
  66.  
  67. struct Window *MainWnd = NULL;
  68. struct TextFont *DFont = NULL;
  69. UWORD *MW_Data;
  70.  
  71. struct EasyStruct ErrorES = {
  72.     sizeof (struct EasyStruct),
  73.     0,
  74.     0l,
  75.     "%s",
  76.     0l,
  77.     };
  78.  
  79. void PlaceWnd( struct Screen *Scr, WORD WndWidth, WORD WndHeight, WORD *x_pos, WORD *y_pos, char Place )
  80.     {
  81.     ULONG             ModeID;
  82.     struct Rectangle  OSRect;
  83.     WORD              ScrWidth = 0, ScrHeight = 0;
  84.  
  85.     if (INVALID_ID != (ModeID = GetVPModeID(&(Scr->ViewPort) ) ) )
  86.         {
  87.         if (QueryOverscan (ModeID, &OSRect, OSCAN_TEXT) )
  88.             {
  89.             ScrWidth = OSRect.MaxX - OSRect.MinX + 1;
  90.             ScrHeight = OSRect.MaxY - OSRect.MinY + 1;
  91.             };
  92.         };
  93.     switch (Place)
  94.         {
  95.         case 0:
  96.             *x_pos = (ScrWidth/2 - WndWidth/2) - Scr->LeftEdge;
  97.             *y_pos = (ScrHeight/2 - WndHeight/2) - Scr->TopEdge;
  98.             break;
  99.         case 1:
  100.             *x_pos = Scr->Width - WndWidth;
  101.             *y_pos = Scr->BarHeight + 1;
  102.             break;
  103.         case 2:
  104.             *x_pos = 0;
  105.             *y_pos = Scr->BarHeight + 1;
  106.             break;
  107.         case 3:
  108.             *x_pos = 0;
  109.             *y_pos = Scr->Height - WndHeight;
  110.             break;
  111.         case 4:
  112.             *x_pos = Scr->Width - WndWidth;
  113.             *y_pos = Scr->Height - WndHeight;
  114.             break;
  115.         }
  116.     }
  117.  
  118. void DrawPlaySymb( int stat )
  119.     {
  120.     switch( stat )
  121.         {
  122.         case 1:
  123.             if (MW_Data) DrawImage( MainWnd->RPort,&PfeilImage, 248, 65+offy );
  124.             break;
  125.         case 0:
  126.             SetAPen( MainWnd->RPort, 1 );
  127.             RectFill( MainWnd->RPort, 248, 65+offy, 262, 70+offy );
  128.             break;
  129.         default:
  130.             if (MW_Data) DrawImage( MainWnd->RPort,&PauseImage, 248, 65+offy );
  131.             break;
  132.         }
  133.     }
  134.  
  135. void DrawPrgmSymb( int stat )
  136.     {
  137.     if (stat)
  138.         {
  139.         if (MW_Data) DrawImage( MainWnd->RPort,&PrgmImage, 218, 65+offy );
  140.         }
  141.     else
  142.         {
  143.         SetAPen( MainWnd->RPort, 1 );
  144.         RectFill( MainWnd->RPort, 218, 65+offy, 240, 70+offy );
  145.         }
  146.     }
  147.  
  148. ErrorMsg(char *Msg)
  149.     {
  150.     ErrorES.es_Title = "MCDP Fehlermeldung:";
  151.     ErrorES.es_GadgetFormat = "Oje";
  152.  
  153.     EasyRequest( MainWnd, &ErrorES, 0, Msg );
  154.     }
  155.  
  156. void CleanMainWnd()
  157.     {
  158.     if (MW_Data) DrawImage( MainWnd->RPort,&MainImage, 5, 12+offy );
  159.     }
  160.  
  161. int OpenMainWnd( char Place )
  162.     {
  163.     struct Screen *Scr;
  164.     UWORD i;
  165.     WORD x, y;
  166.     int Exit = 0;
  167.  
  168.     if (Scr = LockPubScreen( 0 ))
  169.         {
  170.         offy = Scr->WBorTop + Scr->RastPort.TxHeight - 10;
  171.         MainWindowTags[ 9 ].ti_Data = Scr;
  172.         PlaceWnd( Scr, 390, 98+offy, &x, &y, Place );
  173.         MainWindowTags[ 0 ].ti_Data = x;
  174.         MainWindowTags[ 1 ].ti_Data = y;
  175.         MainWindowTags[ 3 ].ti_Data = 98+offy;
  176.     
  177.         if ( MW_Data = (UWORD *)AllocMem( 8148, MEMF_CHIP ) )
  178.             {
  179.             memcpy( MW_Data, MainWinData, 8064 );
  180.             memcpy( ((char *)MW_Data)+8064, PfeilData, 20 );
  181.             memcpy( ((char *)MW_Data)+8084, PauseData, 20 );
  182.             memcpy( ((char *)MW_Data)+8108, PrgmData, 40 );
  183.             PfeilImage.ImageData = ((char *)MW_Data)+8064;
  184.             PauseImage.ImageData = ((char *)MW_Data)+8084;
  185.             PrgmImage.ImageData = ((char *)MW_Data)+8108;
  186.  
  187.             if ( MainWnd = OpenWindowTagList( 0l, MainWindowTags ))
  188.                 {
  189.                 MainImage.ImageData = MW_Data;
  190.                 DrawImage( MainWnd->RPort,&MainImage, 5, 12+offy );
  191.  
  192.                 for (i=0; i<31; i++)
  193.                     {
  194.                     if (MainGadget[i] = (struct Gadget *)AllocMem( sizeof( struct Gadget ), MEMF_CLEAR ))
  195.                         {
  196.                         MainGadget[i]->LeftEdge = gad_x[i]+5;
  197.                         MainGadget[i]->TopEdge  = gad_y[i]+12+offy;
  198.                         MainGadget[i]->Width    = gad_w[i];
  199.                         MainGadget[i]->Height   = gad_h[i];
  200.                         MainGadget[i]->Flags    = GFLG_GADGHCOMP;
  201.                         MainGadget[i]->Activation = GACT_RELVERIFY;
  202.                         MainGadget[i]->GadgetType = GTYP_BOOLGADGET;
  203.                         MainGadget[i]->GadgetID = i;
  204.                         AddGadget( MainWnd, MainGadget[i], ~0 );
  205.                         }
  206.                     else
  207.                         {
  208.                         ErrorMsg( "Fehler bei Erzeugung der Gadgets!" );
  209.                         Exit = 5;
  210.                         }
  211.                     };
  212.                 if (DFont = (struct TextFont *)OpenDiskFont( &DispFont ))
  213.                     {
  214.                     SetFont( MainWnd->RPort, DFont );
  215.                     }
  216.                 else
  217.                     {
  218.                     ErrorMsg( "Kann Zeichensatz nicht öffnen!" );
  219.                     Exit = 4;
  220.                     }
  221.                 }
  222.             else
  223.                 {
  224.                 ErrorMsg( "Kann Fenster nicht öffnen!" );
  225.                 Exit = 1;
  226.                 }
  227.             }
  228.         else
  229.             {
  230.             ErrorMsg( "Speicheranforderung fehlgeschlagen!" );
  231.             Exit = 2;
  232.             }
  233.         UnlockPubScreen( NULL, Scr );
  234.         }
  235.     else
  236.         {
  237.         ErrorMsg( "Kann Screen nicht öffnen!" );
  238.         Exit = 3;
  239.         }
  240.     return ( Exit );
  241.     }
  242.  
  243. CloseMainWnd()
  244.     {
  245.     UWORD i;
  246.  
  247.     if (MW_Data) FreeMem( MW_Data, 8128 );
  248.     if (MainWnd) CloseWindow( MainWnd );
  249.     for (i=0; i<31; i++)
  250.          if (MainGadget[i]) FreeMem( MainGadget[i], sizeof( struct Gadget ) );
  251.     if (DFont) CloseFont( DFont );
  252.     }
  253.  
  254.